0
This is my class connection in the database
class Conection {
private $_host = 'ALISON\MSSQLSERVER2';
private $_user = 'banco';
private $_pass = '123456';
private $_database = 'aulateste';
private $_con;
function __construct(){
$this->conecta();
}
public function conecta() {
$_coninfo = array("Database" =>$this->_database, "UID" =>$this->_user, "PWD" =>$this->_pass);
$_con = sqlsrv_connect($this->_host, $_coninfo);
if($_con) {
echo "Conexão estabelecida";
}else{
echo "Conexão não estabelecida";
die( print_r( sqlsrv_errors(), true));
echo "<br>";
}
}
}
This is my method of insert :
public function cadastrar_autor($Id_autor,$Nome_autor, $Sobrenome_autor){
$sql = "INSERT INTO tbl_autor VALUES($this->Id_autor,$this->Nome_autor,$this->Sobrenome_autor)";
$sql_inserir = sqlsrv_query($sql,$this->conect);
if($sql_inserir > 0){
echo"Cadastrou";
}else{
die( print_r( sqlsrv_errors(), true));
}
}
Error
An invalid Parameter was passed to sqlsrv_query
What is the description of the error message ? you need to edit your question tell us more information about your problem , at which point this error occurs during the execution of the signup() ?
– stringnome
There are other ways to do it but literal values should be in simple quotes.
– rray
Which error appears? invalid syntax for missing single quotes in values? for some value in the Identity field?
– rray
@stringNome An invalid Parameter was passed to sqlsrv_query this is the following error, I did structured in this same segment and it worked, but OO gives this error, I’m new in SQL SERVER did not know that a different database made a big difference in the code, I’m from Mysql
– Alison Paulo
@rray this is the error An invalid Parameter was passed to sqlsrv_query the connection exists but ta with the value of NULL
– Alison Paulo
The correct is
sqlsrv_query($this->conect, $sql);
– rray
already did this, this is the error when I change, sqlsrv_query() expects Parameter 1 to be Resource, Object Given in
– Alison Paulo
Put the code that calls the
inserir()
vc does not store your connection anywhere.– rray
I don’t understand what you mean
– Alison Paulo
Somewhere you call
cadastrar_autor()
puts this code tbm– rray
yes in my view I call the method register the bank class and distinct from the author class
– Alison Paulo
you can put this code in the question?
– rray