I have been messing with this problem for days now. I use a PHP script to enter data into a MySQL database, I get a blank page, or it says it did it, but nothing changes in MySQL. I tried updating from older programs, installing all 32 bit, and installing all 64 bit software. Now that I've updated once and redone everything twice, I am certain I have problem in Windows, but I do not have any idea where to search. I will show you a script I am using, but I know it's a working script as I've used it to test other servers. A major barrier to finding a solution to the problem though, is that every time I find someone with my problem it is largely assumed the script is the problem, I have no error codes, this particular script even says "SUCCESS!"
System: Windows 7 Home Premium SP1 x64 Apache 2.4.7 VC11 x64 PHP 5.5.7 VC11 x64 MySQL Server 5.6.12
Script:
<?php // mysql-pdo-test.php
try {
$user = "[censored]"; $pass = "[censored]";
echo "-->connect and select database\n";
$dbh = new PDO('mysql:host=projectedin.local;dbname=test', $user, $pass);
# activate exception generation
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
echo "<br />-->create table:\n";
$dbh->exec( "CREATE TABLE IF NOT EXISTS test_tab (thing VARCHAR(10))" );
echo "<br />-->insert into table:\n";
$dbh->exec( "INSERT INTO test_tab VALUES ('book'),('pencil')" );
echo "<br />-->select from table:\n";
$res = $dbh->query( "SELECT thing FROM test_tab" );
foreach ($res as $row) {
echo $row['thing'], " ";
}
echo "<br />-->drop table:\n";
$dbh->exec( "DROP TABLE test_tab" );
echo "<br />SUCCESS!";
// disconnect
$dbh = null;
}
catch (PDOException $e) {
die( "<h4>Error: " . $e->getMessage() . "</h4>" );
}
?>
This:
$dbh->exec( "INSERT INTO test_tab VALUES ('book'),('pencil')" );
is not valid. Should be:
$dbh->exec( "INSERT INTO test_tab VALUES ('book', 'pencil')" );
Not sure if that's causing your problem, but it sure isn't helping.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.