PHP error after query in table "Call to Undefined Function mysql_error()"

Asked

Viewed 104 times

0

I have a query data query made in PHP version PHP Version 5.2.4

Where 1 to each N query returns the error :

inserir a descrição da imagem aqui

I believe it’s a punctual Exception, but there must be some way to treat it.

The code line of which the error mentions just after the query consultation:

  $result_conhec = mssql_query($sql_conhec) or die ("E R R O R SQL_OCORR ". mssql_error());
  • 1

    It doesn’t seem that mssql_error() is a valid php function. You could try using mssql_get_last_message http://php.net/manual/en/function.mssql-get-last-message.php

  • mssql or mysql? Review the title.

1 answer

2


First of all, PHP 5.2.4 is quite old, it would really be better to update it, download a newer version of Xampp or Wamp.

Second, your title speaks mysql_error but in your code this mssql_error, soon are different functions, actually mssql_error there is no.

If you want to connect with mysql then use mysqli or PDO with PDO_MYSQL.

If you want to connect with Sqlserver, then use:


Functioning sqlsrv_

<?php
$serverName = 'serverName\nomeDaInstancia';

// SE não definir UID e PWD no $connectionInfoa conexão irá usar a autenticação do Windows.
$connectionInfo = array(
   'UID' => 'usuario',
   'PWD' => 'senha',
   'Database' => 'nomedobanco'
);

$conn = sqlsrv_connect($serverName, $connectionInfo) or die( print_r( sqlsrv_errors(), true));

$sql = 'SELECT * FROM foo WHERE id = ? OR bar = ?';
$params = array(1, 'texto');

$stmt = sqlsrv_query($conn, $sql, $params) or die( print_r( sqlsrv_errors(), true));

sqlsrv_close($conn);

Functioning obdc_:

$driver = 'tipo do driver do servidor cliente';
$server = 'servidor';
$database = 'banco';
$user = 'usuario';
$password = 'senha';

$Conn = odbc_connect("Driver=$driver;Server=$server;Database=$database;", $user, $password) or die("E R R O R CONEXAO " . odbc_errormsg() );

$result = odbc_exec($conn, "SELECT * FROM foo WHERE id = 1 OR bar = 'texto'") or die("E R R O R SQL_OCORR " . odbc_errormsg($conn) );

while (odbc_fetch_row($result)) {
    for ($i=1;$i <= odbc_num_fields($result); $i++) {
        echo "Resultado: " . odbc_result($result, $i);
    }
}

odbc_close($);

With PDO (PDO_ODBC):

$driver = 'tipo do driver do servidor cliente';
$server = 'servidor';
$database = 'banco';
$user = 'usuario';
$password = 'senha';

try {
    $conn = new PDO("odbc:Driver=$driver;SERVERNAME=$server;DATABASE=$database",
          $user, $password);  
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(Exception $e) {
    die( print_r( $e->getMessage() ) );   
}

With PDO (PDO_SQLSRV):

If you’re gonna use this on a Windows hosting/server it will be necessary to install SQLSRV 3.0. If you need support for PHP5.2 or compiled on VC6, use this driver SQLSRV 2.0.

$server = 'servidor';
$database = 'banco';
$user = 'usuario';
$password = 'senha';

try {
    $conn = new PDO("sqlsrv:server=$server;Database=$database", $user, $password);  
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(Exception $e) {
    die( print_r( $e->getMessage() ) );   
}

Note that the variable value $driver in some of the examples will depend on which driver you have installed on your server/hosting and on your local computer (in both may be different drivers), examples of drivers:

$driver = 'FreeTDS'; //Este é usado em algumas hospedagens Linux e Unix (como Mac OSX)
$driver = '{SQL Server}';
$driver = '{SQL Server Native Client 10.0}'; //versão 10
$driver = '{SQL Server Native Client 11.0}'; //versão 11
$driver = '{ODBC Driver 11 for SQL Server}'; //ODBC

Note that there is also an odbc driver for Linux: http://www.microsoft.com/download/en/details.aspx?id=28160

Browser other questions tagged

You are not signed in. Login or sign up in order to post.