mysql_query () does not execute

-1

I am trying to test if my database has connected properly from a query, but apparently mysql_query () does not execute and does not change my table. My code is this:

<?php
//conecta a base de dados
$dbc = mysql_connect('localhost', 'dbweb', 'notime');
if(!$dbc)
{
    die("Not connected : " . mysql_error());
}

//seleciona a base de dados
$db_select = mysql_select_db('goaheadmakemyday', $dbc);
if($db_select)
{
    die("Can't connect : " . mysql_error());
}

//teste
$query = "UPDATE Colaborador SET Nome='Ola' WHERE ColNum='0'";
$resultado = mysql_query($query);

//Pequena parte da minha tabela:
//ColNum  Nome
//0       Simeão Lopes
//1       Olavo Bettencourt
//2       Sandro Vidal
    
asked by anonymous 17.05.2016 / 20:06

1 answer

0

In your code, the problem is when the connection is successful $db_select gets true , enters if and fatally drops in die() and kills your script. The solution to this is to deny the condition or do an inline scan.

The mysql functions have already been removed from php7, it is best to use MySQL or PDO to query the database.

$db_select = mysql_select_db('goaheadmakemyday', $dbc);
if(!$db_select)
{
    die("Can't connect : " . mysql_error());
}

Inline

mysql_select_db('goaheadmakemyday', $dbc) or die(mysql_error());
    
17.05.2016 / 20:16