Jump to content

Search the Community

Showing results for tags 'pdo'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


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

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Found 12 results

  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); } } } }
  2. Hello. I'd just like to enquire about loading a record/entry from a database and decryption. Encryption is fine. To start with I'm rebuilding my login/sign in file (signin.php) to load a record from the registration database, then decrypt the record, to check the email and password fields. All I wanted to enquire is, should I place the decryption code in the signin.php file, or because I'll be accessing the registration database later on in my project as well. Should I place the decryption in a separate php file (say decryption.php for example) and get the signin.php to load the decryption.php file? Any thoughts, or how would any one else go about it? Thank You.
  3. Hi all, I've been working out my learning issues slowly and was able to figure out the process to communicate from html form to PDO to Mariadb fine. I decided to try to work with Prepared Statements via PDO into my Mariadb and am having some probs I can't get through. I'm trying to simplify things as much as possible so I can work it out, but don't think I've got it. Can anyone help point out a better approach to using prepared statements for a simple form with a few q's. I've scaled down my practice files to ease of use. I'm using my own Apache test server locally, w/ latest ver of apache and Mariadb 10.1.26 on windows 8.1 Here is simple html file: <!doctype html> <html lang="en-US"> <!-- ###################################################################################################/--> <!-- Main Page for Monsters of SciFi Tribute -- Testing Only /--> <!-- ###################################################################################################/--> <head> <meta charset="UTF-8"> <title>SciFi Monsters</title> <link href="http://localhost/CheckFormData.php" type="text/php" rel="stylesheet"> </head> <body> <br> <br> <br> <!-- This section is for: Take a quick Godzilla survey /--> <div id="survey-div"> <form action = "CheckFormData.php" method = "post"> <fieldset id="survey-fieldset"> <legend>Take one of our quick surveys.</legend> <p> <label>1. Who is your <strong>favorite monster</strong> character (Godzilla related or not):</label> <input id="FavMonster" name="FavMonster" type="text" value="" /> </p> <p> <label>2. Who is your <strong>favorite villian</strong>:</label> <input id="FavVillian" name="FavVillian" type = "text" /> </p> <p> <label>3. What is your <strong>favorite monster related movie</strong>:</label> <input id="FavMovie" name="FavMovie" type = "text" /> </p> <p> <label>Press 'Submit' when you are done.</label> <input type="submit" value="Submit" name="submit_button" /> </p> </fieldset> </form> </div> </body> </html> Here is my CheckFormData.php test file (what a mess, haha): <!DOCTYPE html> <html lang = "en-US"> <head> <meta charset = "UTF-8"> <title>CheckFormData.php</title> </head> <!-- The attempt with this file is to verify all user entered data is formatted correctly, then establish a database connection, and attempt to communicate that data to the database, all from one file. /--> <body> <?php // define variables and set to empty values // 1st - Set variables for form array $_POST $SurveyForm = $_POST; $Q1 = $SurveyForm['FavMonster']; $Q2 = $SurveyForm['FavVillian']; $Q3 = $SurveyForm['FavMovie']; // Set any functions up // validate all form data function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // We are NOT testing for 'required' fields if ($_SERVER["REQUEST_METHOD"] == "POST") { //Start validation on all Q's test_input($Q1); test_input($Q2); test_input($Q3); // Start move validation if (!preg_match("/^[a-zA-Z ]*$/",$Q1)) { $SQErr = "Only letters and white space allowed"; } if (!preg_match("/^[a-zA-Z ]*$/",$Q2)) { $SQErr = "Only letters and white space allowed"; } if (!preg_match("/^[a-zA-Z ]*$/",$Q3)) { $SQErr = "Only letters and white space allowed"; } } // OK, presuming my validations are working, now attempt to connect to database // PDO connection check $servername = "localhost"; $username = "Any"; $password = "BurgerKing"; $dbname = "test-survey1"; try { //Attempt MySQL server connection $conn = new PDO("mysql:host=$servername; dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Prepare sql and bind parameters $stmt = $conn->prepare("INSERT INTO [test-survey1].favorites (FavMonster, FavVillian, FavMovie) VALUES (:Q1, :Q2, :Q3)"); $stmt->bindParam(':FavMonster', $Q1); $stmt->bindParam(':FavVillian', $Q2); $stmt->bindParam(':FavMovie', $Q3); $Q1; $Q2; $Q3; $stmt->execute(); echo "New records created successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } $conn = null; ?> </body> </html> ** What this all gives me right now is: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
  4. Hi All, I am new to php and I don't about following error. So I request you to give me solution for this and also please explain something about this error. Here I am working on User's profile page. I able to fetch data and displaying in profile's form, but data is not updating and I got the following error when I clicked for "Updation". " Uncaught Error: Call to a member function bindParam() on boolean in C:\xampp\htdocs\VS\components\update-profile.php:16 Stack trace: #0 {main} thrown in C:\xampp\htdocs\VS\components\update-profile.php on line 16 " And my code is: <?php include '../_database/database.php'; ini_set("display_errors",1); session_start(); $msg=""; $temp=(isset($_SESSION['Username']) ? $_SESSION['Username'] : ''); $id=(isset($_SESSION['Id']) ? $_SESSION['Id'] : ''); if($_SERVER["REQUEST_METHOD"] == "POST") { $username = $_POST['Username']; $email = $_POST['Email']; $employee = $_POST['EmployeeID']; $designation = $_POST['Designation']; $password = $_POST['Password']; $sql=$database->prepare("update set Username=:name,Email=:email,EmployeeID=:employee,Designation=:designation,Password=:password where Id='$id'"); $sql->bindParam(':Username',$name,PDO::PARAM_STR, 50); $sql->bindParam(':Email',$email,PDO::PARAM_STR, 50); $sql->bindParam(':EmployeeID',$employee,PDO::PARAM_INT, 11); $sql->bindParam(':Designation',$designation,PDO::PARAM_STR, 50); $sql->bindParam(':Password',$password,PDO::PARAM_STR, 50); if($sql->execute()){ echo "<font face='Verdana' size='2' color=green>You have successfully updated your profile<br></font>"; } else{ print_r($sql->errorInfo()); $msg=" <font face='Verdana' size='2' color=red>There is some problem in updating your profile. Please contact site admin<br></font>"; } } ?> If this is wrong kindly give me a solution. Thank You,
  5. <?php $serv = "localhost:81"; $user = "root"; $password = ""; try { $con = new PDO("mysql:host=$serv;dbname=test", $user, $password); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Successfully connected."; } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?> Here I'm trying to use PDO to connect to my SQL database "test". However, I receive this error each time I connect: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. Am I connecting with the wrong server, user or password? Because I fail to see here the mistake.
  6. I currently am doing a little work on a seasonal website for our golf league and wanted to improve the content with some databases. Going online and reading some articles regarding doing this I came across the issue of whether to write my code using SQL object oriented, SQL procedural or I guess what is the latest and greatest scripting, PDO. What I have read is that if I have any thought of changing over to another database type other than SQL, PDO would be the way to go. But my thought is that I most likely would not because I not only may never deal with other types of databases but I do not think that all these Hosting sites which SQL is most likely ingrained in would change and make their thousands of customers recode all their scripts. “Am I wrong” When I was taught PHP/SQL, I believe it was using the Procedural method, which appears not to be far from the object oriented script. PDO seems to be a little more involved in learning its syntax. What would your recommendations be for me? I would learn the PDO method if you think it would be beneficial. But if not necessary, I will stick to what I already feel comfortable with. All comments greatly appreciated. P
  7. Hello all. I have come here to the source of web standards to understand PHP and the API's it uses to access databases. From my reading (why yes, I do know how to use google ) it seems both MySQLi and PDO are acceptable methods. Other than the boatload of "experts" on various forums and blogs shouting that MySQLi is depreciated, is there any real indication that it is? Now I don't want to start a MySQLi Vs PDO thread. I just want to know if MySQLi is still an acceptable API to use
  8. plus one ("+1") "like button"-voting system I just want to have non-authorization (non-voting "system" at all - just for like button). I want to click "Like"-button key and want to have other users which visit this webpage to see this. Like-button with no additional things (no dislike) just: 1. Press - HTML/Javascript 2. Send PHP (PDO!) 3. Receive Textfile (may be.. mysql) *it has to be as simple as it could be* 4. Show +1, which would be visible to other visitors (ajax/js - optional). That example to be working. I have mysql and apache and php PDO (php5.5.6)! This is with no PDO and I don't think It could work (php5.5.6) and in any case.... The upperscript is not very much comprehensible though, because the only thing I done in PDO was: Considering the upper borrowed example ,I have some speculations: I don't need Ajax for my first steps (at all) - because it's long and lots of unknowns and after all it's increasing complexity. Might it be not a bad idea to refuse to use mysql. I had had a two-week (or so) searching(examination/looking) before js tryings when searching (in English) how to do PDO. (I should say it's a great effort to fight for your little desirable piece of code over an inet). Reminder for myself: 1. Launch mysql: /etc/init.d/mysql start just for likes: 1a) Make a db, make users, grant rights OR 1b) After mysql launch with the help of PHP/PDO: grant mysql rights admin, make a db, make db users & grant them rights to db, make tables and INSERT data INTO tables (may be a single like-table). OR even 1c) Make a textfile - and forget this brain pain and append to it (like I do it in bash >>). 2. Make HTML 2a) <form><input type=button id="likebutton" onClick="databaseinsertevent()"> 2b) ......onClick=Database insert without any functions - just because it is very many text 3. Make JavaScript 3a) something+=something+1 >>like 3b) show like on page 4. Make PHP/PDO or PHP/txt-file 4a) read last line of txt txt 1 2 3 4b) a database (much more complex variant) $db=new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', 'hyuiuik'); foreach($db->query('SELECT like FROM TABBL') as $value) { echo $value['nn']; foreach($db->query('INSERT like TO TABBL') as $something <-- #comment//* Repeat the 1st output 5. Link all modules 5a) HTML + Javascript 5b) html/js + PHP 5c) PHP/PDO + mysql (or a textfile) 5d) run /etc/init.d/apache2 start *5d1 Link apache2+mysql+php(+pdo) (emerge -av php/pdo etc...,config..) if needed ------------------------------------------------- I am in my first steps of a difficult winding climb towards ⬘
  9. hello everyone..how do i code PDO for this script...please help me <?php if (isset($_POST['Login'])){ $UserName=$_POST['UserName']; $Password=$_POST['Password']; $hostname = 'localhost'; $username = 'root'; $password = ''; $database_name = 'ovs'; $mysqli = new mysqli($hostname, $username,$password, $database_name); $login_query=mysqli_query($mysqli,"select * from voters where Username='$UserName' and Password='$Password' and Status='Unvoted' and Year='1st year'") or die(mysqli_error()); $login_query1=mysqli_query($mysqli,"select * from voters where Username='$UserName' and Password='$Password' and Status='Voted'"); $count=mysqli_num_rows($login_query); $count1=mysqli_num_rows($login_query1); $row=mysqli_fetch_assoc($login_query); $id=$row['VoterID']; ?>index.php
  10. Can you tell me what the function of PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ?I've read the php manual, but i still dont understand that...If i remove the setattributte method, it looks alright too... What's the function of that actually ?
  11. hey guys, I'm trying to switch my mysql connections over to PDO but I'm having a hard time. I've read a section on it in the php book I'm reading, I watched the phpacademy,org tutorial on it, I've read the section on it here at w3schools and I can't get it working. I've also posted it on 2 other forums and no one has yet to figure out where the problem is and it's eaten up 2 days of my time as well. If I can't get it figured out today I'm seriously thinking of going back to using the old mysql functions because they worked right the first time and have never given me an ounce of trouble. It's just very frustrating that my registration/login system was working perfect and then I upgrade and nothing works and no one can figure it out. . . It says the error is on line 142, which is the fetchAll() function line. Thanks for any help you guys can offer! Here is the connection script <?php// Connects to Our Database$db_host = "localhost";$db_user = "root";$db_password = "";$db_database = "game_db";try{ $conn = new PDO ('mysql:host=localhost;dbname=game_db', $db_user, $db_password);$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);} catch (PDOException $e) { echo 'ERROR: ' . $e->getMessage();}?> And the query thats giving me the trouble $sql = "INSERT INTO `player_data` (`username`, `empire_name`, `ruler_name`, `founding_group`, `government`, `population`, `currency`, `p_currency`, `scrap`, `food`, `fuel`, `salvage_wpn`, `scrap_wpn`, `morale`, `initiative`, `influence`, `farms`, `housing`, `scrap_yards`, `barracks`, `taverns`, `scouts`, `militia`, `infantry`, `heavy_infantry`, `technicals`, `tanks`, `gate`, `tower`, `wall`, `tunnels`, `dogs`) VALUES (:user, :empire_name, :ruler_name, :founding_group, :government, 25, 1000, 100, 1000, 1000, 0, 0, 5, 10, 100, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)"; $query = $conn->prepare($sql); $query->bindValue(':user', $user, PDO::PARAM_STR); $query->bindValue(':empire_name', $empire_name, PDO::PARAM_STR); $query->bindValue(':ruler_name', $ruler_name, PDO::PARAM_STR); $query->bindValue(':founding_group', $founding_group, PDO::PARAM_STR); $query->bindValue(':government', $government, PDO::PARAM_STR); try { $query->execute(); } catch (Exception $e) { exit($e); } $row_count = $query->fetchAll(PDO::FETCH_ASSOC);
  12. I have read the documentation on php.net about installing the module php-pdo with MySQL support and it seems that it says to use the option--with-pdo-mysql however it does not show me any context on how or where to use it. I have been installing php-pdo on my server with yum -y install php-pdo however that only installs the module with SQLite support. I need to know how to install the module on CentOS 6 with support for MySQL. It seems there are drivers for this. I found know documentation that could explain this to me. Does anyone know how to do this?
  • Create New...