আমি wamp server use করতেসি। আমি php এর নিচের এই script ta lekhar pore kano error dekhai bujte parlam na . কেউ help করলে তাকে অগ্রিম ধন্যবাদ ।

php script:

<?php 
$link = mysqli_connect('localhost', 'root', '');
if (!$link) {
    die('could not connect to the server');
}
$db = mysqli_select_db('tuto',$link);
if (!$db) {
    die('could not connect to the database');
}
$data = "SELECT * FROM user";

$data_query = mysql_query($data, $link);

$value = mysql_fetch_array($data_query);
print_r($value);

?>

error show:

Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\wamp\www\php-tutorial\index.php on line 6

asked 14 Apr '15, 00:57

shadat501's gravatar image

shadat501
317

edited 14 Apr '15, 01:05


আপনি এখানে mysqli আর mysql একসাথে গুলায় ফেলছেন । আপনাকে যে কোন একটি ব্যাবহার করতে হবে ।

নীচের যে কোন একটি ।

$db = mysqli_connect('localhost', 'root', '','tuto');


if (!$db) {
    die('could not connect to the database');
}
$data = "SELECT * FROM user";

$data_query = mysqli_query($db, $data);

$value = mysqli_fetch_array($data_query);
print_r($value);

অথবা

$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('could not connect to the server');
}
$db = mysql_select_db('tuto');
if (!$db) {
    die('could not connect to the database');
}
$data = "SELECT * FROM user";

$data_query = mysql_query($data);

$value = mysql_fetch_array($data_query);
print_r($value);

তবে প্রথম পদ্ধতি ব্যাবহার করা উচিত ।

permanent link

answered 14 Apr '15, 02:50

Sharif%20Chowdhury's gravatar image

Sharif Chowdhury
3.5k111

edited 14 Apr '15, 03:24

Thanks for your helpful answer.

(14 Apr '15, 03:13) shadat501

Please do not use mysql_* it is deprecated

(26 May '15, 15:42) shaiful

The error message tells you what mistake you did.If you see the documentation mysqli_select_db function takes two argument first one is a link identifier mysqli type and second one is the database name string type.

You used first parameter string type(database name) which should be mysqli type. That's why it produces that error.

permanent link

answered 26 May '15, 16:30

shaiful's gravatar image

shaiful
(suspended)

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×217
×73
×60
×5
×4

question asked: 14 Apr '15, 00:57

question was seen: 2,120 times

last updated: 26 May '15, 16:30