| | |
php mysql and pdo
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 140
Reputation:
Solved Threads: 2
Hi all,
I have a pdo connection script to mysql, which works fine. What im a little stuck on is that when i "include" the file, its connected, but how do i call the table to which my query is related to?
The first snippet is the connection, and the second is the insert file.
Im not new to PHP, but i am to OO.
and
I have a pdo connection script to mysql, which works fine. What im a little stuck on is that when i "include" the file, its connected, but how do i call the table to which my query is related to?
The first snippet is the connection, and the second is the insert file.
Im not new to PHP, but i am to OO.
PHP Syntax (Toggle Plain Text)
<?php /*** mysql hostname ***/ $hostname = 'localhost'; /*** mysql username ***/ $username = 'root'; /*** mysql password ***/ $password = 'root'; try { $dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password); /*** echo a message saying we have connected ***/ echo 'Connected to database'; } catch(PDOException $e) { echo $e->getMessage(); } ?>
and
PHP Syntax (Toggle Plain Text)
<?php require("includes/connectpdomysql.php"); if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email'])) { //Prevent SQL injections $username = mysql_real_escape_string($_POST['username']); $email = mysql_real_escape_string($_POST['email']); //Get MD5 hash of password $password = md5($_POST['password']); //Check to see if username exists $sql = mysql_query("SELECT username FROM user WHERE username = 'username'"); If (mysql_num_rows($sql = 0)) { die ("Username taken."); } mysql_query("INSERT INTO users (username, password, email) VALUES ( '$username', '$password', '$email')") or die (mysql_error()); echo "Account created."; } ?> <html></html> <form action="newuser.php" method="post"> Username: <input name="username" type="text" /> Password: <input type="password" name="password" /> Email: <input name="email" type="text" /> <input type="submit" value="Submit" /> </form>
0
#2 Oct 22nd, 2009
What do you mean by calling the table? Also, why're you using PDO for the connection then just completely ignoring it and using mysql_query anyway? http://php.net/pdo
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
![]() |
Similar Threads
- Looking for PHP / MySQL Developer (Web Development Job Offers)
- Looking for a PHP/MYSQL Programmer (Web Development Job Offers)
- Need Highly Experienced PHP/MySQL Programmer $15-$25/hour (Web Development Job Offers)
- PHP/MySQL Programmer Position (Web Development Job Offers)
Other Threads in the PHP Forum
- Previous Thread: Efficient php/mysql Coding
- Next Thread: Integrating vbulletin and elite ladders
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend






