Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

PHP PDO SQLSRV Issue

Custom Title Activated
Loyal Member
Joined
Mar 26, 2012
Messages
1,465
Reaction score
130
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,318
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
130
@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