Probleme avec la fonction sqlsrv_query() pour php/sqlserver 2008
Bonjour,
J'ai un souci avec la fonction sqlsrv_query() depuis 2 jours et ça rend fou :arf:!!!
En fait, j'ai un formulaire avec des données à saisir et via ce formulaire, les données doivent être enregistrées dans une base de données sqlserver 2008. A chaque fois que je valide le formulaire, j'ai l'erreur suivante sachant que la connexion est réussi:
Connection established.
Warning: sqlsrv_query() expects parameter 1 to be resource, object given in D:\Program Files\EasyPHP-5.3.6.0\www\base\abc.php on line 36
Erreur. Pas d'enregistrement effectuéArray ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -14 [code] => -14 [2] => An invalid parameter was passed to sqlsrv_query. [message] => An invalid parameter was passed to sqlsrv_query. ) )
Voici le code du formulaire:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
<html>
<form id="Registre Personnes" name="Registre Personnes" method="POST" action="abc.php">
<p>
<label for="CNAP"><strong>CNAP</strong></label>
<input type="text" name="CNAP" id="CNAP" />
<p>
<label for="Nom"><strong>Nom</strong></label>
<input type="text" name="Nom" id="Nom" />
</span></p>
<p>
<label for="Prenom"><strong>Prenom</strong></label>
<input type="text" name="Prenom" id="Prenom" />
</span></p>
<p>
<label for="Sexe"><strong>Sexe</strong></label>
<select name="Sexe" id="Sexe">
<option>Masculin</option>
<option>Feminin</option>
</select>
</p>
<p>
<label for="Date_de_Naissance"><strong>Date de Naissance</strong></label>
<input onclick="ds_sh(this);" type="text" name="Date_de_Naissance" id="Date_de_Naissance" style="cursor: text"/>
<p>
<label for="Date_de_Creation"><strong>Date de Creation</strong></label>
<input onclick="ds_sh(this);" type="text" name="Date_de_Creation" id="Date_de_Creation" style="cursor: text"/>
<p>
<input type="submit" name="button" id="button" value="Valider" />
<input type="reset" name="button2" id="button2" value="Réinitialiser" />
</form>
</html> |
Voici le fichier php de traitement:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
<?php
# FileName="Connection_php_mysql.htm"
# Type="SQLSERVER"
# HTTP="true"
$Mainconnect = "KGR50\SQLEXPRESS";
$database_Mainconnect = "alpha_db";
$username_Mainconnect = "alpha";
$password_Mainconnect = "gamma";
/*
Connect to the local server using Windows Authentication and specify
the AdventureWorks database as the database in use. To connect using
SQL Server Authentication, set values for the "UID" and "PWD"
attributes in the $connectionInfo parameter. For example:
*/
$connectionInfo = array("UID" =>$username_Mainconnect, "PWD" =>$password_Mainconnect, "Database"=>$database_Mainconnect);
/*$serverName = $hostname_Mainconnect;*/
$conn = new PDO("sqlsrv:server=$Mainconnect;database=$database_Mainconnect",$username_Mainconnect,$password_Mainconnect);
if($conn)
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
}
//-----------------------------------------------
// Perform operations with connection.
//-----------------------------------------------
$insertSQL="INSERT INTO registre_personnes (CNAP, Nom, Prenom, Sexe, Date_de_Naissance, Date_de_Creation)
VALUES ('$_POST[CNAP]','$_POST[Nom]','$_POST[Prenom]','$_POST[Sexe]','$_POST[Date_de_Naissance]','$_POST[Date_de_Creation]')";
if(sqlsrv_query($conn,$insertSQL))
{
echo "Enregistrement effectué";
}
else
{
echo "Erreur. Pas d'enregistrement effectué";
die(print_r(sqlsrv_errors(),true));
}
?> |
Merci pour votre aide !!!!
Probleme avec la fonction sqlsrv_query() pour php/sqlserver 2008
Merci de ta réponse, mais pourrais-tu modifier le code pour que je puisse voir si possible. Merci.
Probleme avec la fonction sqlsrv_query() pour php/sqlserver 2008
Pourrais-tu modifier mon code en haut stp :oops:, car je suis super novice avec SQLServer 2008. J'ai l'habitude de bosser avec Oracle ou Mysql. Merci.
Probleme avec la fonction sqlsrv_query() pour php/sqlserver 2008
Voila ce que j'obtiens quand je fais la modif:
Code:
1 2 3
|
Connection established.
Fatal error: Non-static method PDO::exec() cannot be called statically in D:\Program Files\EasyPHP-5.3.6.0\www\base\abc.php on line 36 |
Probleme avec la fonction sqlsrv_query() pour php/sqlserver 2008
Salut, pour ta question, c'est la première fois que j'utilise SQL server. Je ne suis pas trop fan des outils microsoft !!!
Probleme avec la fonction sqlsrv_query() pour php/sqlserver 2008
J'ai refait la partie php et il ne m'affiche pas d'erreurs. Par contre, mes donnees ne sont pas sauvegardés :?:?.
Voici la partie php:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
<?php
# FileName="Connection_php_mysql.htm"
# Type="SQLSERVER"
# HTTP="true"
$Mainconnect = "KGR50\SQLEXPRESS";
$database_Mainconnect = "alpha_db";
$username_Mainconnect = "alpha";
$password_Mainconnect = "gamma";
/*
Connect to the local server using Windows Authentication and specify
the AdventureWorks database as the database in use. To connect using
SQL Server Authentication, set values for the "UID" and "PWD"
attributes in the $connectionInfo parameter. For example:
*/
$connectionInfo = array("UID" =>$username_Mainconnect, "PWD" =>$password_Mainconnect, "Database"=>$database_Mainconnect);
/*$serverName = $hostname_Mainconnect;*/
$conn = new PDO("sqlsrv:server=$Mainconnect;database=$database_Mainconnect",$username_Mainconnect,$password_Mainconnect);
if($conn)
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
}
//-----------------------------------------------
// Perform operations with connection.
//-----------------------------------------------
$CNAP='$_POST[CNAP]';
$Nom='$_POST[Nom]';
$Prenom='$_POST[Prenom]';
$Sexe='$_POST[Sexe]';
$Date_de_Naissance='$_POST[Date_de_Naissance]';
$Date_de_Creation='$_POST[Date_de_Creation]';
$insertSQL="INSERT INTO registre_personnes (CNAP, Nom, Prenom, Sexe, Date_de_Naissance, Date_de_Creation)
VALUES ($CNAP,$Nom,$Prenom,$Sexe,$Date_de_Naissance,$Date_de_Creation)";
$query=$conn->prepare($insertSQL);
$query->execute(array($CNAP, $Nom, $Prenom, $Sexe, $Date_de_Naissance, $Date_de_Creation));
?> |
Merci pour ton aide.
Probleme avec la fonction sqlsrv_query() pour php/sqlserver 2008
Tu ne penses pas que ça irai plus vite si tu corrigeais directement le code ???
Probleme avec la fonction sqlsrv_query() pour php/sqlserver 2008
J'ai suivi tes conseils et voilà le code. Si tu peux, essayes de me le corriger stp.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
<?php
# FileName="Connection_php_mysql.htm"
# Type="SQLSERVER"
# HTTP="true"
$Mainconnect = "KGR50\SQLEXPRESS";
$database_Mainconnect = "alpha_db";
$username_Mainconnect = "alpha";
$password_Mainconnect = "gamma";
/*
Connect to the local server using Windows Authentication and specify
the AdventureWorks database as the database in use. To connect using
SQL Server Authentication, set values for the "UID" and "PWD"
attributes in the $connectionInfo parameter. For example:
*/
$connectionInfo = array("UID" =>$username_Mainconnect, "PWD" =>$password_Mainconnect, "Database"=>$database_Mainconnect);
/*$serverName = $hostname_Mainconnect;*/
$conn = sqlsrv_connect($Mainconnect,$connectionInfo );
if( $conn )
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
//-----------------------------------------------
// Perform operations with connection.
//-----------------------------------------------
/* Close the connection. */
sqlsrv_close( $conn);
$CNAP='$_POST[CNAP]';
$Nom='$_POST[Nom]';
$Prenom='$_POST[Prenom]';
$Sexe='$_POST[Sexe]';
$Date_de_Naissance='$_POST[Date_de_Naissance]';
$Date_de_Creation='$_POST[Date_de_Creation]';
$insertSQL="INSERT INTO registre_personnes (ID_Interne, CNAP, Nom, Prenom, Sexe, Date_de_Naissance, Date_de_Creation)
VALUES ($ID_Interne,$CNAP,$Nom,$Prenom,$Sexe,$Date_de_Naissance,$Date_de_Creation)";
$params=array($CNAP, $Nom, $Prenom, $Sexe, $Date_de_Naissance, $Date_de_Creation);
$query = sqlsrv_query( $conn,$insertSQL,$params);
?> |
Probleme avec la fonction sqlsrv_query() pour php/sqlserver 2008
Voilà, mais rien n'est sauvegardé dans SQLserver jusqu'à présent.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
<?php
# FileName="Connection_php_mysql.htm"
# Type="SQLSERVER"
# HTTP="true"
$Mainconnect = "KGR50\SQLEXPRESS";
$database_Mainconnect = "alpha_db";
$username_Mainconnect = "alpha";
$password_Mainconnect = "gamma";
/*
Connect to the local server using Windows Authentication and specify
the AdventureWorks database as the database in use. To connect using
SQL Server Authentication, set values for the "UID" and "PWD"
attributes in the $connectionInfo parameter. For example:
*/
$connectionInfo = array("UID" =>$username_Mainconnect, "PWD" =>$password_Mainconnect, "Database"=>$database_Mainconnect);
/*$serverName = $hostname_Mainconnect;*/
$conn = sqlsrv_connect($Mainconnect,$connectionInfo );
if( $conn )
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
//-----------------------------------------------
// Perform operations with connection.
//-----------------------------------------------
$CNAP='$_POST[CNAP]';
$Nom='$_POST[Nom]';
$Prenom='$_POST[Prenom]';
$Sexe='$_POST[Sexe]';
$Date_de_Naissance='$_POST[Date_de_Naissance]';
$Date_de_Creation='$_POST[Date_de_Creation]';
$insertSQL="INSERT INTO registre_personnes ( CNAP, Nom, Prenom, Sexe, Date_de_Naissance, Date_de_Creation)
VALUES ($ID_Interne,$CNAP,$Nom,$Prenom,$Sexe,$Date_de_Naissance,$Date_de_Creation)";
$params=array($CNAP, $Nom, $Prenom, $Sexe, $Date_de_Naissance, $Date_de_Creation);
$query = sqlsrv_query( $conn,$insertSQL,$params);
/* Close the connection. */
sqlsrv_close( $conn);
?> |
Probleme avec la fonction sqlsrv_query() pour php/sqlserver 2008
Merci pour ton aide. Je suis fatigué et je passe à autre chose.
Bonne journée.
Aidez moi pour comprendre
bonsoir à tous,
J'essaye de comprendre le bout de code suivant :
sqlsrv_query ( resource $conn , string $sql [, array $params [, array $options ]] )
L'attribut params : je le comprends pas du tout
Merci pour votre aide d'avance