如何第一次創建 mysqli 數據庫? (how can I creates a mysqli database for first the first time?)


問題描述

如何第一次創建 mysqli 數據庫? (how can I creates a mysqli database for first the first time?)

I was running an example from a mysqli tutorial.

$mysqli = new mysqli("localhost", "user", "password", "database");
if($mysqli‑>connect_errno)
{
  echo "Failed to connect to MySQL: (" . $mysqli‑>connect_errno . ) "
  . $mysqli‑>connect_error;} echo $mysqli‑>host_info . "\n";
} 

I was getting the error:

  

Warning: mysqli::mysqli(): (42000/1049): Unknown database 'world' in /home/...

What should I do to create the database?

‑‑‑‑‑

參考解法

方法 1:

You have to use this:

$mysqli=new mysqli("localhost","user","password") or die(".........");

if($mysqli‑>query("Create database if not exists MyDB")){

   "Failed creating new database: ".$mysqli‑>connect_errno();
    die();

}

$mysqli‑>select_db("MyDB");
$mysqli‑>close();

方法 2:

try something like this 

$mysqli = new mysqli("localhost", "user", "password");

in this way you are connected to database

and put this query using mysqli Create Database database1

(by user1421176Franciscomaxjackie)

參考文件

  1. how can I creates a mysqli database for first the first time? (CC BY‑SA 3.0/4.0)

#mysqli #PHP






相關問題

如何第一次創建 mysqli 數據庫? (how can I creates a mysqli database for first the first time?)

使用 jquery autosuggest 從多個表中選擇 (select from multiple tables with jquery autosuggest)

無法連接 - 數據庫或編碼錯誤 (Could Not Connect - Database or Coding Error)

mysqli忽略表中的第一行 (mysqli ignoring the first row in a table)

從數據庫導入的鏈接以 UTF8 截斷 (imported link from database cut off at UTF8)

試圖獲取非對象的屬性 (Trying to get property of non-object)

獲取 php 和 mysqli 中插入數據的 ID (Get Id of inserted data in php and mysqli)

WAMP 和 mysqli::real_connect(): (HY000/2002)? (WAMP and mysqli::real_connect(): (HY000/2002)?)

如何將 MySQLi 準備好的語句的結果放入關聯數組中? (How can I put the results of a MySQLi prepared statement into an associative array?)

測試選擇查詢是否找到結果 (Testing if a Select Query found results)

為什麼我的正確連接嘗試在 apache2 下失敗但在 cli 下失敗? (Why is my correct connection attempt failing under apache2 but not under cli?)

在帶有數組的 IN 語句之後,在 WHERE 語句中使用更多佔位符 (Use more placeholders in WHERE statement after IN statement with arrays)







留言討論