PHP PDO SQLSRV Issue

Results 1 to 5 of 5
  1. #1
    Tantra/Web Development jbeitz107 is offline
    True MemberRank
    Mar 2012 Join Date
    USALocation
    1,360Posts

    config PHP PDO SQLSRV Issue

    PHP Code:
    $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.


  2. #2
    Programmer TimeBomb is offline
    ModeratorRank
    May 2008 Join Date
    United StatesLocation
    1,264Posts

    Re: PHP PDO SQLSRV Issue

    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 Code:
    $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'$datePDO::PARAM_STR); // or date(...) instead of $date
    $first_bind->bindParam(':userId'$userIdPDO::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?

  3. #3
    Deep thoughts PHP PDO SQLSRV Issue Joopie is offline
    Alpha MaleRank
    Jun 2010 Join Date
    The NetherlandsLocation
    2,661Posts

    Re: PHP PDO SQLSRV Issue

    You need to create an instance of the PDO class first (PHP: PDO::__construct - Manual). Also make sure you have the right drivers/extentions installed for your PHP version.

  4. #4
    Tantra/Web Development jbeitz107 is offline
    True MemberRank
    Mar 2012 Join Date
    USALocation
    1,360Posts

    Re: PHP PDO SQLSRV Issue

    @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.

  5. #5
    :-) s-p-n is offline
    DeveloperRank
    Jun 2007 Join Date
    Next DoorLocation
    2,155Posts

    Re: PHP PDO SQLSRV Issue

    I haven't used PHP in a while, but isn't PDO::execute a method? If it is, you're not invoking it, try `$update = $first_bind->execute()`



Advertisement