Jump to content

Search the Community

Showing results for tags 'execute'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 1 result

  1. I have a challenge to solve regarding PDO and executing prepared statements inside a class. The way I made the script now is giving an error as output, though the outcome required is okay. The error type is: Fatal error: Uncaught ArgumentCountError: Too few arguments to function fruit_stock::get_fruit(), 0 passed in Could it be the error is caused because PHP requires that the execute() part should be defined or something like that? I really dont get what to do with it or with $stmt . . This are the scripts and the table so you can test it yourself. I'm curious how this is done. database table : -- phpMyAdmin SQL Dump -- version 4.7.4 -- https://www.phpmyadmin.net/ -- -- Host: localhost:3306 -- Generation Time: Oct 04, 2018 at 08:42 AM -- Server version: 5.7.19 -- PHP Version: 7.1.9 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `test_fruit` -- -- -------------------------------------------------------- -- -- Table structure for table `fruit` -- DROP TABLE IF EXISTS `fruit`; CREATE TABLE IF NOT EXISTS `fruit` ( `rec_nr` int(2) NOT NULL AUTO_INCREMENT, `fruit_type` varchar(50) DEFAULT NULL, `amount` int(3) NOT NULL, `created_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `changed_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`rec_nr`,`created_on`,`changed_on`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; -- -- Dumping data for table `fruit` -- INSERT INTO `fruit` (`rec_nr`, `fruit_type`, `amount`, `created_on`, `changed_on`) VALUES (1, 'apple', 5, '2018-10-04 06:01:48', '2018-10-04 06:01:48'), (2, 'strawberry', 20, '2018-10-04 06:01:48', '2018-10-04 06:01:48'), (2, 'banana', 15, '2018-10-04 06:02:54', '2018-10-04 06:02:54'), (4, 'grapes', 9, '2018-10-04 06:02:54', '2018-10-04 06:02:54'); COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; Script 1: <?php // run class $amount = '20' ; include 'fruit-class1.php'; $tel_wrg = new fruit_stock('$amount'); $tel_wrg -> get_fruit($amount); var_dump($tel_wrg); echo $tel_wrg -> get_fruit(); ?> Script 2 : <?php // test classes class fruit_stock { var $amount; public $get_fruit; public function get_fruit($amount ) { var_dump($amount); var_dump($this); $servername = "your host"; $username = "your name"; $password = "your password"; $dbname = "test_fruit"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // PREPARED if ($stmt = $conn->prepare("SELECT fruit_type FROM fruit WHERE amount = ? ; " )) { $stmt->bind_param('i', $amount); // $stmt->execute(); $stmt->bind_result($fruit_type); while ($stmt->fetch()) { var_dump($fruit_type); } } } }
×