Database

Updated on January 10, 2018 in Swift 3
12 on October 26, 2017

Hello, I know The Swift Guy has made tutorials on how to use firebase, core data and user defaults to store data. I wonder if it’s possible to use SQL as database because I have experience with it and are comfortable with how it works

 
  • Liked by
Reply
6 on October 26, 2017

Check this out 🙂

on January 2, 2018

Hi – I like the link to the iPhone / My SQL DB you posted. I’m new to PHP and My SQL and Swift as well, so please bear with me. My question is this – I get the following reported when I go to my DB to test if the PHP part is working. Could anyone point out watch the glitch is? I have put part of the php lines at the bottom. Any help appreciated.

Warning: mysqli_connect() [function.mysqli-connect]: Headers and client library minor version mismatch. Headers:50623 Library:100130 in /home/arkrites/public_html/service.php on line 4

Note : If you follow the narrative on his webpage you will recognise the following:[{“Name”:”Apple”,”Address”:”1 Infinite Loop Cupertino, CA”,”Latitude”:”37.331741″,”Longitude”:”-122.030333″},{“Name”:”Googleplex”,”Address”:”1600 Ampitheatre Pkwy, Mountain View, CA”,”Latitude”:”37.421999″,”Longitude”:”-122.083954″}]

 

<?php

// Create connection
$con = mysqli_connect(“localhost”,”arkrites_****”,”*****”,”arkrites_*****”);

// Check connection
if (mysqli_connect_errno())
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}

****** denote names and passwords etc. that have been hidden for security purposes

on January 2, 2018

I think your problem is that you have forgotten ”new” in
$con = new mysqli_connect(your serverinfo)

on January 5, 2018

While JonatanRosell’s answer is correct, I don’t believe it will solve your Problem. The Problem you’re having is that the MySQL and the MySQL Library you’re using have a version Mismatch. You’re using MySQL v5.6.23 and the Library isn’t compatible with it. To solve this you’ll have to up- or downgrade one of the two to have a version Match.

Here you’ll find what other people did: 

https://stackoverflow.com/questions/10759334/headers-and-client-library-minor-version-mismatch

Good Luck!

on January 5, 2018

Unfortunately “new mysql…..”  didn’t solve the problem but this script using PDO works perfectly :

<?php
// start session
// create connection
try {
    $conn = new PDO(“mysql:host=$servername;dbname=$dbname”, $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $conn->prepare(“SELECT * FROM Locations”); 
    $stmt->execute();
// set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
    $resultArray = array();
    foreach(($stmt->fetchAll()) as $k=>$v)
    { 
        array_push($resultArray, $v);
    }
echo json_encode($resultArray);
} // End Try
 
// If there is an error
catch(PDOException $e) 
{
    echo “Error: ” . $e->getMessage();
}
 
// close PDO
$conn = null;
 
// End session
?>

 

 

on January 6, 2018

Hmm okey my bad, btw if you are new to swift and php I would recommend you to use anorher database than mysql because it’s very much code to do small things

on January 10, 2018

As I said, the problem is within the version Mismatch, as I explained above.

@JonatanRosell, good to know!

Show more replies
  • Liked by
Reply
Cancel
0 on October 26, 2017

Thank you very much for that link, it was exactly what I needed 🙂

  • Liked by
Reply
Cancel
3 on November 10, 2017

Recently started using Realm and it seems pretty legit so far

on November 10, 2017

Did a quick-search on google what Realm is, it’s a database, but as i understood isn’t it mySQL? Msybe should check it out anyway

on November 11, 2017

It is a database.  But it’s pretty to implement.  I’m still learning with it as well but so far so good lol. 

 

on November 11, 2017

I will check it out

Show more replies
  • Liked by
Reply
Cancel
Loading more replies