PHP and MySqli. Problem connecting to table

3

I'm following a toturial, everything looks the same. My problem is that I can not connect to the table.

connect.php:

<?php

    $db = new mysqli('127.0.0.1', 'user', 'pass', 'app');

    if ($db -> connect_errno) {
        die ('Sorry, we are having some problems.');
    }

?>

This works correctly, the connection to the DB is done without probs.

The problem is here:

index.php

<?php
    require_once('db/connect.php');

    $result = $db->query("SELECT * FROM people") or die ($db->error);

    if ($result->num_rows) {
        echo 'yay';
    }
?>

The query gives this error message being this:

  

Table 'app.people' does not exist

Being that, only people is the name of the table

    
asked by anonymous 23.06.2014 / 14:05

2 answers

1

The connection syntax is:

$mysqli = new mysqli("meu_host", "meu_usuário", "minha_senha", "meu_banco");

So in your case, the error is stating that the people table does not exist in the app database, make sure that this table exists in your app database. See more ...

    
23.06.2014 / 14:13
1

That's how it worked for me:

connect.php

<?php
// Mantenha o @, ele esconde o echo automatico do erro
$mysqli = @new mysqli("127.0.0.1", "user", "pass", "app");

/* checar conexão */
if (mysqli_connect_errno()) {
    printf("Erro ao contectar:: %s\n", mysqli_connect_error());
    exit();
}


index.php

<?php
require_once('db/connect.php');

/* Executar query */
$result = $db->query("SELECT * FROM people");

/* Checar se a query teve sucesso */
if (!$result) {
    printf("Erro ao executar query: %s\n", $db->error);
}

/* Pegar o numero de linhas */
$rows=mysqli_num_rows($result);

/* Checar se o numero de linhas selecionadas é maior que 0 */
if ($rows>0) {
    echo 'Yay';
}

If it still does not work check the db permissions or try an online server ...

    
28.06.2014 / 21:20