P
P
PO6OT2016-09-18 18:48:33
PHP
PO6OT, 2016-09-18 18:48:33

What's wrong with the code? MySQL query not correct?

<?php
const N = "\n";
if(!$mysqli = @mysqli_connect('127.0.0.1', 'root', 'password', 'site'))
  exit('Fatal error: Couldn\'t connect to MySQL DB.');
if(mysqli_num_rows(mysqli_query($mysqli, 'SHOW TABLES LIKE `users`')) == 0) {
  mysqli_query($mysqli,
    'CREATE TABLE `users` ('.N.
    '    `id` int(11) unsigned NOT NULL auto_increment,'.N.
    '    `email` varchar(30) NOT NULL,'.N.
    '    `password` varchar(32) NOT NULL,'.N.
    '    PRIMARY KEY (`id`)'.N.
    ') ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'
  );
}

For some reason, it mysqli_query()returns false, although the request is valid. What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2016-09-18
@woonem

Duc is, telepaths are all busy. mysqli_error says what?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question