Hack Forums
[PHP] how to use break in mysqli - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] how to use break in mysqli (/showthread.php?tid=5796933)



how to use break in mysqli - SharoKurdi - Feb 8, 2018

hi 😅
i want use Break in mysqli Connect But I cant I get This Error


Code
PHP Parse error:  syntax error, unexpected 'break' (T_BREAK)


THis mysql Connect Code

PHP Code

<?php 
$conn
=@mysqli_connect('localhost','root','1234') or break; 


i dont want use DIE i want Break it But i cant



THnx


RE: how to use break in mysqli - RumbleFrog - Feb 8, 2018

Why would you use break if you don't know what it's designed for? A break is meant to be used within a loop, termination inside of a loop.


RE: how to use break in mysqli - SharoKurdi - Feb 8, 2018

(Feb 8, 2018 06:14 PM)RumbleFrog Wrote:  Why would you use break if you don't know what it's designed for? A break is meant to be used within a loop, termination inside of a loop.


i make loop for 5 server if server 1 is offline break to server 2

:/


RE: how to use break in mysqli - RumbleFrog - Feb 8, 2018

(Feb 8, 2018 06:32 PM)SharoKurdi Wrote:  i make loop for 5 server if server 1 is offline break to server 2

:/

Mind breaking the full loop code then? And it's not break, it's continue.


RE: how to use break in mysqli - SharoKurdi - Feb 9, 2018

(Feb 8, 2018 07:37 PM)RumbleFrog Wrote:  Mind breaking the full loop code then? And it's not break, it's continue.


yas But both not work


RE: how to use break in mysqli - Charger - Feb 9, 2018

Don’t do it like that. Do if/If else statements.


RE: how to use break in mysqli - RumbleFrog - Feb 10, 2018

(Feb 9, 2018 06:56 PM)SharoKurdi Wrote:  yas But both not work

Mind providing the loop code, holy shit.


RE: how to use break in mysqli - Charger - Feb 10, 2018

Do this man:
PHP Code

<?php 
$servers 
= array(
  array(
"Host" => 'localhost',"User" => 'root', "Pass" => '1234'),
 array(
"Host" => 'localhost2',"User" => 'root3', "Pass" => '1234'),
  array(
"Host" => 'localhost3',"User" => 'root3', "Pass" => '1234')
);

$connection = null;
foreach(
$servers as $server)
{
  
$check = @mysqli_connect($server["Host"],$server["User"],$server["Pass"]);
  if(
$check)
    {
      
$connection = $check;
      break;
    }
}
if(
$connection == null)
{
 die(
"Unable to find a database server that is alive");
}
//Your code 



RE: how to use break in mysqli - SharoKurdi - Feb 12, 2018

(Feb 10, 2018 11:04 AM)Charger Wrote:  Do this man:
PHP Code

<?php 
$servers 
= array(
 
 array("Host" => 'localhost',"User" => 'root', "Pass" => '1234'),
 array(
"Host" => 'localhost2',"User" => 'root3', "Pass" => '1234'),
 
 array("Host" => 'localhost3',"User" => 'root3', "Pass" => '1234')
);

$connection = null;
foreach(
$servers as $server)
{
 
 $check = @mysqli_connect($server["Host"],$server["User"],$server["Pass"]);
 
 if($check)
 
   {
 
     $connection = $check;
 
     break;
 
   }
}
if(
$connection == null)
{
 die(
"Unable to find a database server that is alive");
}
//Your code 


thnx for reply problem Connect Freez in connection code if server not Found
PHP Code

<?php 
$check 
= @mysqli_connect($server["Host"],$server["User"],$server["Pass"]); 
i change to Pdo its faster and bypass errors and freez

thnx For Help


RE: how to use break in mysqli - Charger - Feb 12, 2018

(Feb 12, 2018 09:07 AM)SharoKurdi Wrote:  thnx for reply   problem Connect Freez  in  connection code  if  server not Found  
PHP Code

<?php 
 $check 
= @mysqli_connect($server["Host"],$server["User"],$server["Pass"]); 
i change to Pdo  its faster  and   bypass errors  and  freez  

thnx For Help

PDO is much better than mysqli_. Glad this solution worked for you.
Feel free to post a new thread if you have any further issues/questions.


RE: how to use break in mysqli - blackcoder00 - Feb 16, 2018

(Feb 12, 2018 01:31 PM)Charger Wrote:  PDO is much better than mysqli_. Glad this solution worked for you.
Feel free to post a new thread if you have any further issues/questions.
PHP Code

<?php 
$conn
=@mysqli_connect('localhost','root','1234') or die('cannot connect');