Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]MYSQL na MYSQLI czyli przejscie z wersji php 5 na php 7
Zenobiusz
post 7.02.2020, 13:29:12
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 17.05.2019

Ostrzeżenie: (0%)
-----


Pojawiają się błędy:

Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in /pistolet.php on line 34

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /pistolet.php on line 36

Warning: mysqli_error() expects exactly 1 parameter, 0 given in /pistolet.php on line 36

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

<?php require_once('Connections/pistolet.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 5) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysqli_real_escape_string($theValue) : mysqli_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysqli_select_db($database_pistolet, $pistolet);
$query_Recordset1 = "SELECT * FROM pistolety";
$Recordset1 = mysqli_query($query_Recordset1, $pistolet) or die(mysqli_error());
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysqli_num_rows($Recordset1);


if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `pistolety` WHERE CONCAT(`ID`, `pistolet`, `marka`, `ilosc`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);

}
else {
$query = "SELECT * FROM `pistolety`";
$search_result = filterTable($query);
}

// function to connect and execute the query
function filterTable($query)
{
// $connect = mysqli_connect("localhost", "XXXXX", "XXXXX", "XXXXX");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}

?>

<!DOCTYPE html>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<html>
<head>
<title>PHP HTML TABLE DATA SEARCH</title>
<style>
table,tr,th,td
{
border: 1px solid black;
}
</style>
</head>
<body>

<form action="pistolet.php" method="post">
<input type="text" name="valueToSearch" placeholder="Value To Search"><br><br>
<input type="submit" name="search" value="Filter"><br><br>

<table width="60%" align="center">
<tr>
<th width="12%">ID</th>
<th width="28%">pistolet</th>
<th width="28%">marka</th>
<th width="32%">ilość</th>
<th width="32%"></th>
</tr>

<!-- populate table from mysql database -->
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td align="center"><?php echo $row['ID'];?></td>
<td align="center"><?php echo $row['pistolet'];?></td>
<td align="center"><?php echo $row['marka'];?></td>
<td align="center"><?php echo $row['ilosc'];?></td>
<td align="center"><a href="rekordd.php?ID=<?php echo $row['ID']; ?>"><img src="image/delete.png" width="20" height="16"></a></td>
</tr>
<?php endwhile;?>
</table>
</form>

</body>
</html><?php
mysql_free_result($Recordset1);
?>
Go to the top of the page
+Quote Post
nospor
post 7.02.2020, 13:34:56
Post #2





Grupa: Moderatorzy
Postów: 36 441
Pomógł: 6290
Dołączył: 27.12.2004




Czego nie rozumiesz
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in /pistolet.php on line 34
?
Przeciez wyraznie masz napisane, ze mysql_select_db jako pierwszy wynik oczekuje mysqli a nie tekstu. Zobaczy do manualu co masz tam wstawic jak nie rozumiesz. przeciez tam masz przyklady co jest wstawiane


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
Zenobiusz
post 10.02.2020, 09:31:41
Post #3





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 17.05.2019

Ostrzeżenie: (0%)
-----


To może będziesz tak łaskawy i mi to napiszesz ? Przecież od tego jest te forum ? Próbowałem na różne sposoby i miałem nadal bład.

Ten post edytował Zenobiusz 10.02.2020, 09:32:47
Go to the top of the page
+Quote Post
Pyton_000
post 10.02.2020, 09:44:30
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Cytat(Zenobiusz @ 10.02.2020, 09:31:41 ) *
To może będziesz tak łaskawy i mi to napiszesz ? Przecież od tego jest te forum ? Próbowałem na różne sposoby i miałem nadal bład.

I jescze pretensje ma...

Proszę: http://php.net/ tu masz manual. Wyszukaj soboie interesującą funkcję i poczytaj.
Go to the top of the page
+Quote Post
viking
post 10.02.2020, 09:45:14
Post #5





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


A skąd my mamy wiedzieć co to jest u ciebie jakieś $database_pistolet? Rób var_dumpy i porównaj sobie typy z dokumentacji.
https://prophp.pl/advice/show/14/jak_czytac...mentacje_php%3F


--------------------
Go to the top of the page
+Quote Post
Zenobiusz
post 10.02.2020, 10:44:40
Post #6





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 17.05.2019

Ostrzeżenie: (0%)
-----


Cytat
Przeciez wyraznie masz napisane, ze mysql_select_db jako pierwszy wynik oczekuje mysqli a nie tekstu


mysqli_select_db()

Czyli co mam napisać. Napisz proszę dla przykładu.

Go to the top of the page
+Quote Post
nospor
post 10.02.2020, 10:45:57
Post #7





Grupa: Moderatorzy
Postów: 36 441
Pomógł: 6290
Dołączył: 27.12.2004




Dla przykladu masz wyrazne kodu w manualu. Tam masz wlasnie przyklady. Czemu ich nie uzyjesz?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
Zenobiusz
post 10.02.2020, 11:37:20
Post #8





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 17.05.2019

Ostrzeżenie: (0%)
-----


Dopiero zaczynam ten uczyć się PHP a wy do mnie piszecie jak do magistra. Może tak podacie przykład i wyjaśnicie co i dlaczego tak akurat jest ? W końcu to jest forum pomocy.
Go to the top of the page
+Quote Post
nospor
post 10.02.2020, 11:42:27
Post #9





Grupa: Moderatorzy
Postów: 36 441
Pomógł: 6290
Dołączył: 27.12.2004




Marudzisz jak male dziecko... Jaki magister?questionmark.gif?

https://www.php.net/manual/en/mysqli.select-db.php
Przyklad z tej wlasnie strony

  1. $link = mysqli_connect("localhost", "my_user", "my_password", "test");
  2. //....
  3. mysqli_select_db($link, "world");

masz wyraznie napisane, jak masz wywolac mysqli_select_db(). Masz wyraznie napisane, ze pierwszy argument to wynik mysqli_connect(). I tyle. Tu nei trzeba miec doktoratu z fizyki termojadrowej by przepisac to co jest w manualu.

I skoro sie dopiero uczysz, to zacznij od nauki jak uzywac manuala. Bez tego nie ruszych dalej i tylko bedziesz latal po forach z kazda pierda. Nie na tym polega programowanie i nie na tym polegaja fora by podawac ci to co jest podane w manualu


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
Zenobiusz
post 10.02.2020, 11:59:52
Post #10





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 17.05.2019

Ostrzeżenie: (0%)
-----


Dobra dziękuje. Zaraz sprawdzę ale wydaje mi się że tak robiłem i nadal występował błąd. Dam znać.
Go to the top of the page
+Quote Post
nospor
post 10.02.2020, 12:02:58
Post #11





Grupa: Moderatorzy
Postów: 36 441
Pomógł: 6290
Dołączył: 27.12.2004




Cytat
Zaraz sprawdzę ale wydaje mi się że tak robiłem i nadal występował błąd
Kolejna rzecz do nauki: jak php ci mowi, ze wkladasz string to znaczy ze wkladasz string. To nie php sie myli, tylko ty cos robisz zle. Przyjmij ten fakt, a bedzie ci sie latwiej programowalo w przyszlosci wink.gif


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
Zenobiusz
post 10.02.2020, 13:58:57
Post #12





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 17.05.2019

Ostrzeżenie: (0%)
-----


Warning: mysqli_query() expects parameter 1 to be mysqli, string given in


mysqli_select_db($pistolet, "XXXXX");
$query_Recordset1 = "SELECT * FROM pistolety";
$Recordset1 = mysqli_query($query_Recordset1, $pistolet) or die(mysqli_error($pistolet));
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysqli_num_rows($Recordset1);

Dwa błędy poprawiłem ale mimo że są dwa parametry mysqli_query() nadal pojawia się błąd.
Go to the top of the page
+Quote Post
viking
post 10.02.2020, 14:09:47
Post #13





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Zapoznałeś się z artykułem?
Kod
mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] ) : mixed

Pierwszy ma być obiektem mysql, drugi stringiem zapytania.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 16.04.2024 - 20:14