Click here to Skip to main content
15,898,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i create this code it work with phpmyadmin but when i try to connect to ms ssl server i have this error PHP fatal error - Call to a member function prepare() on resource
what i need to edit to work in sql server

What I have tried:

<?php include 'connectionDetails.php'; ?>

<?php


if (isset($_POST['noteid1'], $_POST['notetext1'])) 
{
    var_dump($_POST['notetext1']);

    $stmt = $conn->prepare("UPDATE Notes SET Note = ? WHERE NoteID = ?");
    $stmt->bind_param("si", $notetext2, $noteid2);

    $noteid2 = $_POST['noteid1'];
    $notetext2 = $_POST['notetext1'];
    $stmt->execute();

    $stmt->close();
}
else
{
    if (isset($_POST['notetext1'])) {
        var_dump($notetext2);
    }
    else
    {
        echo "Test";
    }

}


?>
connectionDetails.php:

<?php
$myServer = "test ip";
$connectionInfo = array('Database' => 'DiscoverThePlanet', 'UID' => 'Test', 'PWD' => 'Test');

//connection to the database
$conn = sqlsrv_connect($myServer, $connectionInfo)
  or die("Couldn't connect to SQL Server on $myServer"); 

//Test connection to server
// if ($conn) 
// {
//     echo "connection successful";    # code...
// }

?>
///The error is in the submitNoteText.php and is this line://

$stmt = $conn->prepare("UPDATE Notes SET Note = ? WHERE NoteID = ?");
Posted
Updated 13-Oct-21 3:30am
Comments
Richard MacCutchan 13-Oct-21 9:27am    
Please show the exact text of the error message, and which line of code it occurs on.

1 solution

Your $conn variable is populated with the result of sqlsrv_connect() which is a resource and not a class. To use the $conn variable you'd need to use the sqlsrv_ functions, such as:
PHP
$results = sqlsrv_query($conn, "your query");

The methods that you're describing look like they're from the PDO[^] class, which you create using new PDO(..); instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900