• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

PHP PDO SQLSRV Issue

Custom Title Activated
Loyal Member
Joined
Mar 26, 2012
Messages
1,465
Reaction score
131
PHP:
$hostname="SERVERNAME\SQLEXPRESS";
$dbname="User";
$username='SERVERNAME';
$password='MYPASSWORD';
$first_bind = $conn->prepare("UPDATE Account  SET Birthday = '23-01-1978 00:00:00' WHERE UserID = 'test'");
$update = $first_bind->execute;

When I run this script manually in SQL Server the database updates so I assume it is something to do with php. Anyhow the issue is that everything else updates with no problems but, the datetime field will not update or even insert into the database. Any suggestions would be greatly appreciated.
 
Joined
May 23, 2008
Messages
1,071
Reaction score
574
It's good practice and I highly recommend you to set all column values as statement parameters in your SQL query when using prepared statements.
PHP:
$hostname="SERVERNAME\SQLEXPRESS";
$dbname="User";
$username='SERVERNAME';
$password='MYPASSWORD';
$userId = 123;
$date = 'whatever';
$first_bind = $conn->prepare("UPDATE Account SET Birthday = :birthday WHERE UserID = :userId");
$first_bind->bindParam(':birthday', $date, PDO::PARAM_STR); // or date(...) instead of $date
$first_bind->bindParam(':userId', $userId, PDO::PARAM_STR); // or PDO::PARAM_INT if your user id is a number
$update = $first_bind->execute;

Consider trying to use the PHP date function instead of a string, in case that helps. Though I don't know why a properly formatted string wouldn't work in a datetime column. Are you getting any errors?
 
Joined
Jun 23, 2010
Messages
2,324
Reaction score
2,195
You need to create an instance of the PDO class first ( ). Also make sure you have the right drivers/extentions installed for your PHP version.
 
Custom Title Activated
Loyal Member
Joined
Mar 26, 2012
Messages
1,465
Reaction score
131
@TimeBomb - I have used the date function of php but, only posted in here for reference. I can update fields that only consist of date but, not those of datetime. That is my issue at this time. Thank you for at least responding.
 
Back
Top