Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statement Success Or Not #15

Open
dimaslanjaka opened this issue Mar 2, 2019 · 3 comments
Open

Statement Success Or Not #15

dimaslanjaka opened this issue Mar 2, 2019 · 3 comments
Assignees
Labels

Comments

@dimaslanjaka
Copy link

how can i determine query are success or not ?
some like if ($execute = DB->query(blablabla)){} ?

@lincanbin
Copy link
Owner

lincanbin commented Mar 2, 2019

It returns the number of rows changed, deleted, or inserted by the last statement if it was an UPDATE , DELETE , or INSERT.

if ($DB->query("INSERT balabalabalabala") > 0) {
    // success
} else {
    // not
}

@lincanbin lincanbin self-assigned this Mar 2, 2019
@marcus-hiles
Copy link

@dimaslanjaka in addition to @lincanbin's answer, you can put your execute statement in a try catch block, so if there's any execution error error, you can detect it. Eg.

try {
    if ($DB->query("INSERT balabalabalabala") > 0) {
        // success
    } else {
        // not
   }
} catch (PDOException $e) {
	//codes to run upon getting execution error, goes here 
}

@dimaslanjaka
Copy link
Author

okay guys i understand, thank your help sweety

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants